package cn.tedu.controller;

import cn.tedu.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class IndexController {
    @Autowired
    IndexService indexService;

    @PutMapping("{indexName}")
    public String addIndex(@PathVariable String indexName) {
        indexService.addIndex(indexName);
        return "put " + indexName + " success";
    }

    @GetMapping("{indexName}")
    public String queryIndex(@PathVariable String indexName) {
        return "get " + indexName + " success";
    }

    @DeleteMapping("{indexName}")
    public String deleteIndex(@PathVariable String indexName) {
        return "delete " + indexName + " success";
    }

    @PostMapping("{indexName}")
    public String updateIndex(@PathVariable String indexName) {
        return "post " + indexName + " success";
    }

    /**
     * 搜索
     */
    @GetMapping("search/{indexName}")
    public String searchDoc(@PathVariable String indexName, String fieldName, String text) {
        return indexService.search(indexName, fieldName, text);
    }
}
